import { InjectionKey } from 'vue'
import { createStore, Store, useStore as baseUseStore } from 'vuex'



// 为 store state 声明类型
interface Nav {

}
export interface State {
    count: number,
    currentNavPage: number
}

// 定义 injection key
export const key: InjectionKey<Store<State>> = Symbol()

export const store = createStore<State>({
    state: {
        count: 0,
        currentNavPage: 1
    },
    mutations: {
        increment(state, index) {
            state.currentNavPage = index
        }
    },
    actions: {
        increment(context, index) {
            context.commit('increment', index)
        }
    },
    getters: {
        getCount(state) {
            return state.currentNavPage
        }
    }
})

// 定义自己的 `useStore` 组合式函数
export function useStore() {
    return baseUseStore(key)
}